package org.ezplatform.office.forum.web.rest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.ezplatform.cloud.common.log.LogService;
import org.ezplatform.core.service.BaseService;
import org.ezplatform.core.web.controller.BaseController;
import org.ezplatform.core.web.view.OperationResult;
import org.ezplatform.office.forum.entity.ForumIntegralRule;
import org.ezplatform.office.forum.service.ForumIntegralRuleService;
import org.ezplatform.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 论坛积分规则控制类
 * 2020年09月22日17:40:59
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "/api/w/forum/integralrule")
public class ForumIntegralRuleWebApiController extends BaseController<ForumIntegralRule, String> {
	
    private final Logger log = LoggerFactory.getLogger(ForumIntegralRuleWebApiController.class);
    
    @Autowired
    private ForumIntegralRuleService forumIntegralRuleService;
    
    @Autowired
	private LogService logService;

    @Override
    protected BaseService<ForumIntegralRule, String> getEntityService() {
        return forumIntegralRuleService;
    }
    
    /**
     * 初始化数据
     * @param request
     * @param model
     * @param id
     */
    @ModelAttribute
    public void prepareModel(HttpServletRequest request, Model model,
                             @RequestParam(value = "id", required = false) String id) {
        super.initPrepareModel(request, model, id);
    }
    
    /**
     * 保存论坛积分规则设置
     * @param entity
     * @param request
     * @param model
     * @return
     */
    @RequestMapping(value = "/editIntegralRule", method = RequestMethod.POST)
    @ResponseBody
    public OperationResult editIntegralRule(@ModelAttribute("entity") ForumIntegralRule entity, HttpServletRequest request, Model model){
    	return super.editSave(entity);
    }
    
    /**
     * 查询论坛积分规则详情
     * @param request
     * @return
     */
    @RequestMapping(value = "/getIntegralRuleInfo", method = RequestMethod.GET)
	@ResponseBody
	public OperationResult getIntegralRuleInfo(HttpServletRequest request){
        Map map = new HashMap();
        List<ForumIntegralRule> list = forumIntegralRuleService.getForumIntegralRule();
        if(list.size()>0) {
        	map.put("forumIntegralRule", list.get(0));
        }else {
        	map.put("forumIntegralRule", new ForumIntegralRule());
        }
        return OperationResult.buildSuccessResult(map);
	}
    
}